package players;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import model.OthelloBoard;
import model.Position;

public class HumanPlayer implements Player 
{

	public boolean move(OthelloBoard board, byte color) 
	{
		ArrayList<Position> moves = board.getTransitions(color);
		if (moves.size() == 0)
		{
			return false;
		}
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int i, j;
		Position pos = null;
		try 
		{
			do
			{
				System.out.println("what position to play? \"i j\"");
				String[] splitted = in.readLine().split(" ");
				i = Integer.parseInt(splitted[0]);
				j = Integer.parseInt(splitted[1]);
			} while((pos = getPossibleMove(i,j, moves)) != null);
		} catch (IOException e) 
		{
			e.printStackTrace();
			i = 0;
			j = 0;
		}
		board.makeTransition(pos, color);
		return true;
	}
	
	private Position getPossibleMove(int i, int j, ArrayList<Position> moves)
	{
		for(Position move : moves) 
		{
			if(move.x == i && move.y == j) 
			{
				return move;
			}
		}	
		return null;
	}

	public double evaluate(OthelloBoard board, byte color) 
	{
		return 0.0;
	}
	
	public String toString()
	{
		return "Human";
	}
	
	@Override
	public void setExploration(boolean aan) {
		// TODO Auto-generated method stub
		
	}
}

